/*
 * This file is part of aion-engine <aion-engine.com>
 *
 * aion-engine is private software: you can redistribute it and or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Private Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aion-engine is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License
 * along with aion-engine.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionengine.gameserver.model.templates.item;

import com.aionengine.gameserver.model.Gender;
import com.aionengine.gameserver.utils.stats.AbyssRankEnum;
import com.aionengine.gameserver.world.zone.ZoneName;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

/**
 * @author Rolandas
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UseLimits")
public class ItemUseLimits {

    @XmlAttribute(name = "usedelay")
    private int useDelay;

    @XmlAttribute(name = "usedelayid")
    private int useDelayId;

    @XmlAttribute(name = "ownership_world")
    private int ownershipWorldId;

    @XmlAttribute
    private String usearea;

    @XmlAttribute(name = "gender")
    private Gender genderPermitted;

    @XmlAttribute(name = "ride_usable")
    private Boolean rideUsable;

    @XmlAttribute(name = "rank_min")
    private int minRank;

    @XmlAttribute(name = "rank_max")
    private int maxRank = AbyssRankEnum.SUPREME_COMMANDER.getId();

    @XmlAttribute(name = "guild_level")
    private int guildLevel;

    public int getDelayId() {
        return useDelayId;
    }

    public void setDelayId(int delayId) {
        useDelayId = delayId;
    }

    public int getDelayTime() {
        return useDelay;
    }

    public void setDelayTime(int useDelay) {
        this.useDelay = useDelay;
    }

    public ZoneName getUseArea() {
        if (this.usearea == null)
            return null;

        try {
            return ZoneName.get(this.usearea);
        } catch (Exception e) {
            return null;
        }
    }

    public int getOwnershipWorld() {
        return ownershipWorldId;
    }

    public Gender getGenderPermitted() {
        return genderPermitted;
    }

    public boolean isRideUsable() {
        if (rideUsable == null)
            return false;
        return rideUsable;
    }

    public int getMinRank() {
        return minRank;
    }

    public int getMaxRank() {
        return maxRank;
    }

    public boolean verifyRank(int rank) {
        return minRank <= rank && maxRank >= rank;
    }

    public int getGuildLevelPermitted() {
        return guildLevel;
    }
}
